package com.isoft.demo.controller;

import com.isoft.demo.common.ResponseData;
import com.isoft.demo.entity.CustomerInfo;
import com.isoft.demo.service.CustomerService;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@CrossOrigin
public class CustomerController {

    @Resource
    private CustomerService customerService;

    @PostMapping("/add")
    public ResponseData addCustomer(CustomerInfo customerInfo){
        ResponseData rs = customerService.addCustomer(customerInfo);
        return rs;
    }
    @GetMapping("/update")
    public ResponseData updateCustomer(CustomerInfo customerInfo){
        ResponseData rs = customerService.updateCustomer(customerInfo);
        return rs;
    }
    @GetMapping("/delete")
    public ResponseData deleteCustomer(@Param(value = "cid") int cid){
        ResponseData rs = customerService.deleteCustomer(cid);
        return rs;
    }
    @GetMapping( "/all")
    public ResponseData findAll(){
        ResponseData rs = customerService.findAll();
        return rs;
    }

    @PostMapping("/login")
    public ResponseData login(CustomerInfo customerInfo){
        ResponseData rs = customerService.login(customerInfo);
        return rs;
    }
    @GetMapping("byCid")
    public ResponseData findByCid(Integer cid){
        ResponseData rs = customerService.findById(cid);
        return rs;
    }
    @GetMapping("/updateCus")
    public ResponseData updateCus(CustomerInfo customerInfo){
        ResponseData rs = customerService.updateCus(customerInfo);
        return  rs;
    }
}
